<template>
  <div class="dashboard-container">
    <!-- 第一栏 -->
    <div id="main" style="width: 50%; height: 500px"></div>
    <!-- 第二栏 -->
    <div id="main2" style="width: 50%; height: 500px"></div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getList, getCreditList } from "@/api/visual/analyse";
import * as echarts from "echarts";

export default {
  name: "Dashboard",
  data() {
    return {
      // 雷达图
      myChart: "",
      option: {},
      // 饼图
      myChart2: "",
      option2: {},
    };
  },
  computed: {
    ...mapGetters(["name"]),
  },
  created() {},
  mounted() {
    this.myChart = echarts.init(document.getElementById("main"));
    getList().then((res) => {
      var data = res.data;
      this.init(data);
      this.option && this.myChart.setOption(this.option);
    });
    this.myChart2 = echarts.init(document.getElementById("main2"));
    getCreditList().then((res) => {
      var data = res.data;
      this.init2(data);
      this.option2 && this.myChart2.setOption(this.option2);
    });

    window.addEventListener("resize", () => {
      this.myChart.resize();
      this.myChart2.resize();
    });
  },
  methods: {
    init(data) {
      this.option = {
        title: {
          text: "担保情况数据",
          subtext: "Colla Data",
          top: 10,
          left: 50,
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          type: "scroll",
          bottom: 10,
        },
        visualMap: {
          top: "middle",
          right: 10,
          color: ["red", "blue"],
          calculable: true,
          max: 10,
        },
        radar: {
          indicator: [
            { text: "房产情况", max: 10 },
            { text: "车辆情况", max: 10 },
            { text: "股票情况", max: 10 },
            { text: "债券情况", max: 10 },
          ],
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        series: {
          type: "radar",
          symbol: "none",
          lineStyle: {
            width: 1,
          },
          emphasis: {
            areaStyle: {
              color: "rgba(0,250,0,0.3)",
            },
          },
          data,
        },
      };
    },
    init2(data) {
      this.option2 = {
        title: {
          text: "信用情况数据",
          subtext: "Credit Data",
          top: 10,
          left: 100,
        },
        legend: {
          type: "scroll",
          top: "bottom",
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        series: [
          {
            name: "信用情况数据",
            type: "pie",
            radius: [40, 200],
            center: ["50%", "50%"],
            roseType: "area",
            itemStyle: {
              borderRadius: 8,
            },
            data,
          },
        ],
      };
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 40px 50px;
    display: flex;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
